#!/bin/bash

# 所有服务名称
SERVICES=("auth" "book" "borrow" "eureka" "gateway" "frontend" "grafana/grafana" "postgres:17-alpine" "prom/prometheus" "openzipkin/zipkin")

# 所有 K3s 节点 IP
NODES=("192.168.64.33" "192.168.64.35" "192.168.64.36")

# SSH 用户
SSH_USER="ubuntu"

# 遍历每个节点和服务，将镜像导入到对应节点
for NODE in "${NODES[@]}"; do
  echo "👉 正在向节点 $NODE 导入镜像..."
  for SERVICE in "${SERVICES[@]}"; do
    echo "  📦 传输服务 $SERVICE 的镜像..."
    docker save "$SERVICE" | ssh "${SSH_USER}@${NODE}" "sudo k3s ctr images import -"
  done
done

echo "✅ 所有镜像已导入到所有节点。"